package com.example.demo.config.builder.choice;

import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.guard.Guard;

import com.example.demo.app.entity.FormEntity;
import com.example.demo.config.enum_.ComplexFormEvents;
import com.example.demo.config.enum_.ComplexFormStates;
import com.example.demo.utils.RedisUtil;

/**
 * 分支判断
 * @author hello
 *
 */
public class ComplexFormCheckChoiceGuard implements Guard<ComplexFormStates, ComplexFormEvents>{
	@Override
	public boolean evaluate(StateContext<ComplexFormStates, ComplexFormEvents> context) {
		System.out.println("验证表单必填项开始====》");
		boolean returnValue = false;
		FormEntity form = context.getMessage().getHeaders().get("form", FormEntity.class);
		if (form== null  || form.getId() == null || form.getName() == null ||  form.getName().equals("") || form.getName().toCharArray().length <10) {
			returnValue = false;
		}else {
			returnValue = true;
		}
		
		System.out.println("验证表单必填项结束====》"+form.toString()+" is "+returnValue);
		return returnValue;
	}
}
